package ferp.core.state;

import ferp.core.game.Game;
import ferp.core.game.Input;
import ferp.core.game.Settings;
import ferp.core.log.Log;
import ferp.core.player.Profile;

/**
 * User: igorgok
 * Date: 10/22/11 9:37 PM
 */
class Initialize extends State
{
  @Override
  public final int process(Game.Listener listener, Profile profile, Game g, Settings settings, Input input) throws Game.Error
  {
    Log.debug(Log.TAG, "initializing mode " + g.mode());

    // initialize the current mode
    int r = g.mode().initialize(listener, profile, g, settings);

    // switch to the "getting input options" state if the current state was not changed by initialize()
    // and we are still in the same mode
    if (g.state() == this)
      g.set(State.gio);

    save(profile);

    return r;
  }
}
